package com.example.suuu.project.system.controller;

import com.example.suuu.project.system.entity.SuMenu;
import com.example.suuu.project.system.entity.vo.UserCodeMenu;
import com.example.suuu.tools.log.LogPrint;
import com.example.suuu.tools.tree.TreeUtils;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.example.suuu.project.system.service.impl.SuMenuServiceImpl;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.CrossOrigin;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import com.example.suuu.model.result.ResultVo;
import com.example.suuu.project.system.query.SuMenuQuery;

import javax.annotation.Resource;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author sun
 * @desc 菜单 API接口
 * @date 2023-06-28
 */
@CrossOrigin
@RestController
@RequestMapping("/suMenu")
@Api(value = "/suMenu", tags = {"菜单 API接口"})
@ApiSupport(author = "sun")
public class SuMenuController {

    @Resource
    public SuMenuServiceImpl suMenuService;


    @PostMapping("/add")
    @LogPrint("菜单新增")
    @ApiOperation(value = "菜单新增", notes = "菜单新增")
    @ApiOperationSupport(ignoreParameters = {"id"})
    public ResultVo add(@Validated @RequestBody SuMenu u) {
        return ResultVo.ResultVoSuccess(suMenuService.add(u));
    }

    @PutMapping("/update")
    @LogPrint("菜单修改")
    @ApiOperation(value = "菜单修改", notes = "菜单修改")
    @ApiOperationSupport(ignoreParameters = {})
    public ResultVo update(@Validated @RequestBody SuMenu u) {
        return ResultVo.ResultVoSuccess(suMenuService.update(u));
    }

    @DeleteMapping("/del/{id}")
    @LogPrint("菜单删除")
    @ApiOperation(value = "菜单删除", notes = "菜单删除")
    public ResultVo del(@Validated @PathVariable(value = "id") Integer id) {
        return ResultVo.ResultVoSuccess(suMenuService.del(id));
    }

    @GetMapping("/getlist")
    @LogPrint("菜单查询")
    @ApiOperation(value = "菜单查询", notes = "菜单查询")
    @ApiOperationSupport(ignoreParameters = {})
    public ResultVo get(SuMenuQuery query) {
        return ResultVo.ResultVoSuccess(suMenuService.pagVo(query));
    }

    @GetMapping("/getById/{id}")
    @LogPrint("菜单id查询")
    @ApiOperation(value = "菜单id查询", notes = "菜单id查询")
    @ApiOperationSupport(ignoreParameters = {})
    public ResultVo getById(@Validated @PathVariable(value = "id") Integer id) {
        return ResultVo.ResultVoSuccess(suMenuService.getById(id));
    }

    @GetMapping("/getByUserCode")
    @LogPrint("用户编号查询菜单")
    @ApiOperation(value = "用户编号查询菜单", notes = "用户编号查询菜单")
    public ResultVo getByUserCode(@Validated UserCodeMenu u) {
        return  ResultVo.ResultVoSuccess(suMenuService.getByUserCodeType(u));

    }
}